import java.net.*;
import java.io.*;
import javax.swing.*;
public class Listener extends Thread
{
    Mazewar mazewar;

	public Listener(Mazewar mazewar)
	{
        this.mazewar = mazewar;
	}

    public void run()
    {
        try
        {
            int port = 0;
            ServerSocket _ListenSocket = new ServerSocket(port);
            mazewar.myself.hostname = _ListenSocket.getInetAddress().getHostName();
            mazewar.myself.port = _ListenSocket.getLocalPort();

            System.err.println("Listening at port # " + _ListenSocket.getLocalPort() + " host: " + mazewar.myself.hostname);

            while (mazewar.keepListening)
            {                
                new ListenHandler(_ListenSocket.accept(), mazewar).start();
            }

            _ListenSocket.close();
            System.err.println("ListenSocket closed()");
        }
        catch (Exception ex)
        {            
            ex.printStackTrace();
        }
    }
}
